import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
  name: 'filter'
})
export class FilterPipe implements PipeTransform {
   //根据传过来的关键词过滤商品数据
  transform(list: any[], filterField: string, keywords: string): any {
    if(!filterField || !keywords) {
      return list;
    }

    return list.filter(item => {
       let filterValue = item[filterField];
       return filterValue.indexOf(keywords) >= 0;
    });
  }

}
